package vip.huhailong.rabbitmqdemo;

import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Envelope;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.support.MessagePropertiesConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import vip.huhailong.rabbitmqdemo.config.ConfirmCallbackConfig;
import vip.huhailong.rabbitmqdemo.config.ReturnCallbackConfig;
import vip.huhailong.rabbitmqdemo.entity.FieldContent2;

import java.util.List;
import java.util.UUID;

/**
 * @author Huhailong
 * @Description
 * @Date 2021/11/18.
 */
@Component
public class RabbitUtil {

    @Autowired
    RabbitTemplate rabbitTemplate;

    public void importFieldContent(List<FieldContent2> list){

        rabbitTemplate.convertAndSend("TestDirectExchange", "TestDirectRouting", list, new MessagePostProcessor() {
            @Override
            public Message postProcessMessage(Message message) throws AmqpException {
                message.getMessageProperties().setMessageId(UUID.randomUUID().toString());
                message.getMessageProperties().setHeader("token", "token_str");
                return message;
            }
        });
    }
}
